 /*
 * Sala.java
 *
 * Created on 5 de Outubro de 2007, 11:01
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package salas;

import java.awt.GridLayout;
import javax.swing.JPanel;

/**
 *
 * @author Juliano
 */
public class Sala extends JPanel {
    
    Poltrona[] poltronas;
    private String nome;
    
    
    /** Creates a new instance of Sala */
    public Sala(int tam, String nome){
        super();
        this.nome = nome;
        poltronas = new Poltrona[tam];        
        this.setLayout(new GridLayout(0,10));
        this.setVisible(true);
        criaPoltronas();
        repaint();
    }
    
    public void criaPoltronas(){
        for (int i=0; i < poltronas.length;i++){
            poltronas[i] = new Poltrona(""+i);
            this.add(poltronas[i]);
        }
    }

    public int posicao(){
        for(int i=0;i<poltronas.length;i++){
             if(poltronas[i].status() && !poltronas[i].reservada())
                return i;
        }
        return -1;
    }
    
    public void poltronaOcup(int i){
        poltronas[i].reservaPoltrona();
        poltronas[i].reserva();
    }
    
    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }
    
}
